#import <misckit/MiscSliderField.h>

#import "StyleInspector.h"
#import "Tree.h"

@implementation StyleInspector

- init
{  
   	[super init];
	view = nil;	
	return self;
}
   
- (BOOL)wantsButtons 
{ 
	return NO; 
}

- (BOOL)doesHandleSelection
{
	char buf[MAXPATHLEN + 1];
    id bundle;
	
	if([self selectionCount] == 1 && [[self selection] isMemberOf:[Tree class]]){
		if(!view){
		 	bundle = [NXBundle mainBundle];
    		[bundle getPath:buf forResource:"StyleInspector" ofType:"nib"];
   			[NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
		}
		return YES;
	}
	return NO;
}

- ok:sender
{
	[(NXColorWell *)fillColor deactivate];
	[(NXColorWell *)textColor deactivate];
	[(NXColorWell *)outlineColor deactivate]; 
	return [super ok:sender];
}

- revert:sender
{
	id tree;
	
	[super revert:sender];
	tree = [self selection];
	[form selectCellAt:[tree pathKind] :0];
	[outline setState:[tree outline]];
	[fillColor setColor:[tree fillColor]];
	[textColor setColor:[tree textColor]];
	[outlineColor setColor:[tree outlineColor]];
	[outlinewidth setFloatValue:[tree linewidth]];
	[nodeEnding selectCellAt:[tree ending] :0];
	[parentEnding selectCellAt:[tree parentEnding] :0];
	[nodeEnding scrollCellToVisible:[tree ending] :0];
	[parentEnding scrollCellToVisible:[tree parentEnding] :0];
	return self;
}

- changeParentEnding:sender
{
	[[self selection] setParentEnding:[[sender selectedCell] tag]];
	return self;
}

- changeNodeEnding:sender
{
	[[self selection] setEnding:[[sender selectedCell] tag]];
	return self;
}

- changeForm:sender
{
	[[self selection] setPathKind:[[sender selectedCell] tag]];
	return self;
}

- changeOutline:sender
{
	[[self selection] setOutline:[sender state]];
	return self;
}

- changeFillColor:sender
{
	[[self selection] setFillColor:[sender color]];
	return self;
}

- changeTextColor:sender
{
	[[self selection] setTextColor:[sender color]];
	return self;
}

- changeOutlineColor:sender
{
	[[self selection] setOutlineColor:[sender color]];
	return self;
}

- changeOutlinewidth:sender
{
	[[self selection] setLinewidth:[sender floatValue]];
	return self;
}
  
@end
